package com.health.system.common.utils;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 */
public class ThrowableUtil {
    private ThrowableUtil() {

    }

    /**
     * 获取堆栈信息
     */
    public static String getStackTrace(Throwable throwable) {
        if (ObjectUtils.isNull(throwable)) {
            return "";
        }

        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        }
    }

}
